﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ModularFixture.CApMFConfigurationTypeData
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EMPAPPSERVICESLib;
using EMPTYPELIBRARYLib;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ModularFixture;

internal class CApMFConfigurationTypeData : CApMFConfigurationData
{
  private string m_plpUsage;
  private TxTransformation m_fixtureUnitOrigin;
  private double m_minToleranceX;
  private double m_maxToleranceX;
  private double m_minToleranceY;
  private double m_maxToleranceY;
  private double m_minToleranceZ;
  private double m_maxToleranceZ;
  private bool m_fixtureUnitOriginSet;

  internal CApMFConfigurationTypeData(string name, string usage, string bitmap)
    : base(name, bitmap)
  {
    this.m_plpUsage = usage;
    this.m_fixtureUnitOrigin = new TxTransformation();
    this.m_minToleranceX = 0.0;
    this.m_maxToleranceX = 0.0;
    this.m_minToleranceY = 0.0;
    this.m_maxToleranceY = 0.0;
    this.m_minToleranceZ = 0.0;
    this.m_maxToleranceZ = 0.0;
    this.m_fixtureUnitOriginSet = false;
  }

  internal CApMFConfigurationTypeData(string name)
    : base(name)
  {
    this.m_fixtureUnitOrigin = new TxTransformation();
    this.m_fixtureUnitOriginSet = false;
  }

  internal void SetToleranceParams(
    double minToleranceX,
    double maxToleranceX,
    double minToleranceY,
    double maxToleranceY,
    double minToleranceZ,
    double maxToleranceZ)
  {
    this.m_minToleranceX = minToleranceX;
    this.m_maxToleranceX = maxToleranceX;
    this.m_minToleranceY = minToleranceY;
    this.m_maxToleranceY = maxToleranceY;
    this.m_minToleranceZ = minToleranceZ;
    this.m_maxToleranceZ = maxToleranceZ;
  }

  internal override void SaveAttributesToEms(int internalId)
  {
    if (!CApMFAdminUtils.ConfirmCheckOut(internalId))
      return;
    this.SaveCommonAttributesToEms(internalId, "Configuration");
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    EmpFieldValue[] empFieldValueArray = new EmpFieldValue[8];
    empFieldValueArray[0].fieldName = "Usage";
    empFieldValueArray[1].fieldName = "FixtureUnitOrigin";
    empFieldValueArray[2].fieldName = "MinToleranceX";
    empFieldValueArray[3].fieldName = "MaxToleranceX";
    empFieldValueArray[4].fieldName = "MinToleranceY";
    empFieldValueArray[5].fieldName = "MaxToleranceY";
    empFieldValueArray[6].fieldName = "MinToleranceZ";
    empFieldValueArray[7].fieldName = "MaxToleranceZ";
    empFieldValueArray[0].FieldValue = (object) this.m_plpUsage;
    empFieldValueArray[2].FieldValue = (object) this.m_minToleranceX;
    empFieldValueArray[3].FieldValue = (object) this.m_maxToleranceX;
    empFieldValueArray[4].FieldValue = (object) this.m_minToleranceY;
    empFieldValueArray[5].FieldValue = (object) this.m_maxToleranceY;
    empFieldValueArray[6].FieldValue = (object) this.m_minToleranceZ;
    empFieldValueArray[7].FieldValue = (object) this.m_maxToleranceZ;
    double[] numArray = new double[6];
    TxVector translation = this.m_fixtureUnitOrigin.Translation;
    numArray[0] = translation.X;
    numArray[1] = translation.Y;
    numArray[2] = translation.Z;
    TxVector rotationRpyXyz = this.m_fixtureUnitOrigin.RotationRPY_XYZ;
    numArray[3] = rotationRpyXyz.X;
    numArray[4] = rotationRpyXyz.Y;
    numArray[5] = rotationRpyXyz.Z;
    empFieldValueArray[1].FieldValue = (object) numArray;
    EmpNodeFieldsValues[] nodeFieldsValuesArray = new EmpNodeFieldsValues[1]
    {
      new EmpNodeFieldsValues()
      {
        Node = {
          objectId = internalId
        },
        FieldsValues = empFieldValueArray
      }
    };
    ((IEmpNodesServices) new EmpNodesServicesClass()).SetFields(ref empContext, ref nodeFieldsValuesArray);
  }

  internal override void LoadAttributesFromEms(int internalId)
  {
    this.LoadCommonAttributesFromEms(internalId);
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    IEmpNodesServices iempNodesServices = (IEmpNodesServices) new EmpNodesServicesClass();
    string[] strArray = new string[8]
    {
      "Usage",
      "FixtureUnitOrigin",
      "MinToleranceX",
      "MaxToleranceX",
      "MinToleranceY",
      "MaxToleranceY",
      "MinToleranceZ",
      "MaxToleranceZ"
    };
    EmpObjectKey[] empObjectKeyArray = new EmpObjectKey[1];
    empObjectKeyArray[0].objectId = internalId;
    EmpFieldInfo[] fields = iempNodesServices.GetFields(ref empContext, ref empObjectKeyArray, ref strArray);
    this.m_plpUsage = (string) fields[0].Value;
    this.m_minToleranceX = (double) fields[2].Value;
    this.m_maxToleranceX = (double) fields[3].Value;
    this.m_minToleranceY = (double) fields[4].Value;
    this.m_maxToleranceY = (double) fields[5].Value;
    this.m_minToleranceZ = (double) fields[6].Value;
    this.m_maxToleranceZ = (double) fields[7].Value;
    double[] numArray = (double[]) fields[1].Value;
    this.m_fixtureUnitOrigin = new TxTransformation(new TxVector(numArray[0], numArray[1], numArray[2]), new TxVector(numArray[3], numArray[4], numArray[5]), (TxTransformation.TxRotationType) 1);
    this.m_fixtureUnitOriginSet = true;
  }

  internal string PlpUsage
  {
    get => this.m_plpUsage;
    set => this.m_plpUsage = value;
  }

  internal TxTransformation FixtureUnitOrigin
  {
    get => this.m_fixtureUnitOrigin;
    set => this.m_fixtureUnitOrigin = value;
  }

  internal bool FixtureUnitOriginSet
  {
    get => this.m_fixtureUnitOriginSet;
    set => this.m_fixtureUnitOriginSet = value;
  }

  internal double MinToleranceX => this.m_minToleranceX;

  internal double MaxToleranceX => this.m_maxToleranceX;

  internal double MinToleranceY => this.m_minToleranceY;

  internal double MaxToleranceY => this.m_maxToleranceY;

  internal double MinToleranceZ => this.m_minToleranceZ;

  internal double MaxToleranceZ => this.m_maxToleranceZ;
}
